def campaign_0():
    Campaign1Group1.LoadCampaign()
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Predict)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Predict, optimizeGoal = 50)    
    Campaign1Group1.StartDialing(optimizeGoal = 80)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Predict, optimizeGoal = 50)    
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign1Group1.StopDialing()
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Predict, optimizeGoal = 50)    
    Campaign1Group1.UnloadCampaign()

def campaign_1():
    Campaign1Group1.LoadCampaign()
    Campaign1Group1.SetDialingMode(optimizeGoal = 50)  
    Campaign1Group1.StartDialing(optimizeGoal = 80)
    DN1.MakeCall(DN2)
    DN1.QueryCall()
    DN1.ReleaseCall()
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Progress)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign1Group1.SetDialingMode(optimizeGoal = 50)    
    Campaign1Group1.StartDialing(optimizeGoal = 80)
    Campaign1Group1.StopDialing()
    Campaign1Group1.UnloadCampaign()



def campaign_and_commdn_1():
  """Pure CMLib requests, CommDN and CMLib objects should receive notifications"""
  Campaign1Group1.LoadCampaign()
  Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
  Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Progress)
  Campaign1Group1.SetDialingMode(optimizeGoal = 60)
  Campaign1Group1.StartDialing(dialMode = CfgDialMode.Predict)  
  Campaign1Group1.StopDialing()
  Campaign1Group1.UnloadCampaign()

def campaign_and_commdn_2():
  """Mix of CMLib and CommDN requests, CommDN and CMLib objects should receive notifications"""
  Campaign1Group1.LoadCampaign()
  Campaign1Group1.SetDialingMode(CmCommunicationDN1,  optimizeGoal = 55)  
  Campaign1Group1.StartDialing()
  Campaign1Group1.StopDialing(CmCommunicationDN1)
  Campaign1Group1.UnloadCampaign(CmCommunicationDN1)

def campaign_and_commdn_3():
  """Pure CommDN requests, CommDN and CMLib objects should receive notifications"""
  Campaign1Group1.LoadCampaign(CmCommunicationDN1)
  Campaign1Group1.SetDialingMode(CmCommunicationDN1, dialMode = CfgDialMode.Preview, optimizeGoal = 40)  
  Campaign1Group1.StartDialing(CmCommunicationDN1)
  Campaign1Group1.StopDialing(CmCommunicationDN1)
  Campaign1Group1.UnloadCampaign(CmCommunicationDN1)

def campaign_and_commdn_3a():
  """Pure CommDN requests, CommDN and CMLib objects should receive notifications"""
  Campaign1Group1.LoadCampaign(CmCommunicationDN1)
  Campaign1Group1.SetDialingMode(CmCommunicationDN1, dialMode = CfgDialMode.Preview, optimizeGoal = 40)
  Campaign1Group1.StartDialing(CmCommunicationDN1)
  Campaign1Group1.StopDialing(CmCommunicationDN1)
  Campaign1Group1.UnloadCampaign(CmCommunicationDN1)
  Campaign1Group1.ForceUnloadCampaign(CmCommunicationDN1) # should be error



def campaign_and_commdn_3b():
  """Pure CommDN requests, CommDN and CMLib objects should receive notifications"""
  Campaign1Group1.LoadCampaign(CmCommunicationDN1)
  Campaign1Group1.SetDialingMode(CmCommunicationDN1, dialMode = CfgDialMode.Predict, optimizeGoal = 40)  
  Campaign1Group1.StartDialing(CmCommunicationDN1)
  Campaign1Group1.SetDialingMode(CmCommunicationDN1, dialMode = CfgDialMode.Predict, optimizeGoal = 40)  
  Campaign1Group1.StopDialing(CmCommunicationDN1)
  Campaign1Group1.ForceUnloadCampaign(CmCommunicationDN1) # should be error
  Campaign1Group1.UnloadCampaign(CmCommunicationDN1)



def sequence_campaign_cmlib_4():
  """CMLib  requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing()
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.DialingStarted()
    Item.DialingStopped()
    Item.Unloaded()

def sequence_campaign_commdn_4():
  """CommDN  requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load(CmCommunicationDN1)
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.DialingStarted()
    Item.DialingStopped()
    Item.Unloaded()

def sequence_campaign_mixed_4():
  """Mixed  requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load(CmCommunicationDN1)
  CampaignSequence1.StartDialing()
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.DialingStarted()
    Item.DialingStopped()
    Item.Unloaded()




def sequence_campaign_cmlib_5():
  """CMLib  requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""
  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 30 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 30 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  csi1 = CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1 )
  csi2 = CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2, sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  csi1.SetDialingMode(dialMode = CfgDialMode.Predict, optMethodValue = 64)
  csi2.SetDialingMode(dialMode = CfgDialMode.Progress, optMethodValue = 78)  
  CampaignSequence1.StartDialing()
  csi1.SetDialingMode(optMethodValue = 64)
  csi2.SetDialingMode(optMethodValue = 78)  
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.DialingStarted()
    Item.SetDialingMode(dialMode = CfgDialMode.Progress, optMethodValue = 30)
    Item.DialingStopped()
    Item.Unloaded()




def sequence_campaign_commdn_5():
  """CommDN requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""
  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 30 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 30 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  csi1 = CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1 )
  csi2 = CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2, sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load(CmCommunicationDN1)
  csi1.SetDialingMode(CmCommunicationDN1, dialMode = CfgDialMode.Predict,  optMethodValue = 64)
  csi2.SetDialingMode(CmCommunicationDN1,  dialMode = CfgDialMode.Preview, optMethodValue = 78)  
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.DialingStarted()
    Item.SetDialingMode(CmCommunicationDN1, dialMode = CfgDialMode.Preview, optMethodValue = 30)
    Item.DialingStopped()
    Item.Unloaded()


def sequence_campaign_mixed_5():
  """Mixed requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""
  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 30 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 30 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  csi1 = CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1 )
  csi2 = CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2, sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load(CmCommunicationDN1)
  csi1.SetDialingMode(optMethodValue = 64)
  csi2.SetDialingMode(optMethodValue = 78)  
  CampaignSequence1.StartDialing()
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.DialingStarted()
    Item.DialingStopped()
    Item.Unloaded()


def sequence_campaign_cmlib_6():
  """CMLib requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing()
  CampaignSequence1.StopDialing()
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.Unloaded()

def sequence_campaign_commdn_6():
  """CMLib requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load(CmCommunicationDN1)
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  CampaignSequence1.StopDialing(CmCommunicationDN1)
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.Unloaded()

def sequence_campaign_mixed_6():
  """Mixed requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  CampaignSequence1.StopDialing()
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.Unloaded()



def sequence_campaign_cmlib_7():
  """CMLib requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing()
  CampaignSequence1.StopDialing()
  CampaignSequence1.Unload()


def sequence_campaign_commdn_7():
  """CommDN requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load(CmCommunicationDN1)
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  CampaignSequence1.StopDialing(CmCommunicationDN1)
  CampaignSequence1.Unload(CmCommunicationDN1)

def sequence_campaign_mixed_7():
  """Mixed requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 20 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  CampaignSequence1.StopDialing()
  CampaignSequence1.Unload(CmCommunicationDN1)


#Error cases

def sequence_campaign_error_mixed_8():
  """Mixed error requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""
  
  # does not work as expected
  return
  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 90 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  CampaignSequence1.StartDialing(CmCommunicationDN1)  # should be error, it is not there
  CampaignSequence1.StopDialing()
  CampaignSequence1.StopDialing(CmCommunicationDN1) # should be error, it is not there
  CampaignSequence1.Unload(CmCommunicationDN1)


def sequence_campaign_error_mixed_9():
  """Mixed error requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""
  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 30 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  CampaignSequence1.StopDialing()
  CampaignSequence1.Load() # should be error
  CampaignSequence1.Load(CmCommunicationDN1) # should be error
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.Unloaded()


def sequence_campaign_error_mixed_10():
  """Mixed error requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""
  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 30 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing(CmCommunicationDN1)
  Campaign1Group1.LoadCampaign(CmCommunicationDN1)
  Campaign1Group1.StartDialing(CmCommunicationDN1)
  Campaign1Group1.StopDialing()
  CampaignSequence1.StopDialing()
  CampaignSequence1.Load() # should be error
  CampaignSequence1.Load(CmCommunicationDN1) # should be error
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.Unloaded()
    

def sequence_campaign_error_mixed_11():
  """Mixed error requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""
  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 30 #sec
  startTime = now + toStartIn 
  timeToWork1 = 40 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 40 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
  

  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  
  Campaign1Group1.LoadCampaign(CmCommunicationDN1)
  CampaignSequence1.Load()  # should be error
  Campaign1Group1.UnloadCampaign()
